# 初始化
import os

import django

from utils.core_initialize import CoreInitialize

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.base')
django.setup()

from system.user.models import Users
from system.role.models import Role
from system.menu.models import Menu, Button


class Initialize(CoreInitialize):
    creator_id = "456b688c-8ad5-46de-bc2e-d41d8047bd42"

    def init_button(self):
        """
        初始化权限表标识
        """
        self.button_data = [
            {"id": "4547b93a-36b9-410d-987c-3c52a9b51156", "name": "编辑", "value": "Update", },
            {"id": "4a410769-6b0a-4ed3-90f0-b5d89a6f802c", "name": "删除", "value": "Delete", },
            {"id": "644e9c34-e3d6-4518-b795-a603a6e9a137", "name": "单例", "value": "Retrieve", },
            {"id": "80cb145b-5035-4517-a28a-7d59426f73f8", "name": "新增", "value": "Create", },
            {"id": "ccc3f35f-c80c-4929-b8cc-67531698f397", "name": "查询", "value": "Search", },
            {"id": "83a9b774-4669-4d2f-b61d-8ee4944c2316", "name": "保存", "value": "Save", },
        ]
        self.save(Button, self.button_data, "权限表标识")

    def init_menu(self):
        """
        初始化菜单表
        """
        self.menu_data = [
            {
                "id": "49ab0373-21a4-475e-a94c-e745f18194fa",
                "name": "system_home",
                "path": "/system/home",
                "component": "system/dashboard/index",
                "title": "工作台",
                "icon": "desktop",
                "sort": 1,
                "status": 1,
                "type": 0
            },
            {
                "id": "8c1243c5-d848-43e8-b98e-d824fb0b43cb",
                "name": "system_setting",
                "path": "/system",
                "redirect": "/system",
                "component": "PageView",
                "title": "系统管理",
                "icon": "setting",
                "show": True,
                "hideChildren": False,
                "sort": 10,
                "status": 1,
                "type": 0
            },
            {
                "id": "0487c5ec-69f1-4aec-b4bb-22cabae0a289",
                "name": "system_menu",
                "path": "/system/menu",
                "component": "system/menu/index",
                "title": "菜单管理",
                "sort": 99,
                "status": 1,
                "type": 1,
                "parent_id": "8c1243c5-d848-43e8-b98e-d824fb0b43cb"
            }
        ]
        self.save(Menu, self.menu_data, "菜单表")

    def init_role(self):
        """
        初始化角色表
        """
        data = []
        self.save(Role, data, "角色表")

    def init_users(self):
        """
        初始化用户表
        """
        data = [
            {"id": "456b688c-8ad5-46de-bc2e-d41d8047bd42",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 1,
             "is_active": 1, "username": "admin", "name": "超级管理员", "email": "207007541@qq.com"
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd243a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo", "name": "demo",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fckd243a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo001", "name": "demo001",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcqd243a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo01", "name": "demo01",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fqdd243a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo2", "name": "demo2",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd443a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo3", "name": "demo3",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcgd243a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo4", "name": "demo4",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd248a7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo5", "name": "demo5",
             }, {"id": "bcb411ce-13ff-4a2a-8eda-fcdd243a7j76",
                 "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
                 "is_superuser": 1, "is_staff": 0,
                 "is_active": 0, "username": "demo6", "name": "demo6",
                 }, {"id": "bcb411ce-13ff-4a2a-8eda-fcdl243a7f76",
                     "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
                     "is_superuser": 1, "is_staff": 0,
                     "is_active": 0, "username": "demo7", "name": "demo7",
                     },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd243a7m76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo8", "name": "demo8",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd243a9f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo9", "name": "demo9",
             },
            {"id": "bcb411ce-13ff-4a2a-8eda-fcdd243l7f76",
             "password": "pbkdf2_sha256$150000$3ytA08I7qKHG$HxVwGXxpvIlRugaLGnMm38gK38ZwgB/DMIxdBssNp28=",
             "is_superuser": 1, "is_staff": 0,
             "is_active": 0, "username": "demo10", "name": "demo10",
             },

        ]
        self.save(Users, data, "用户表", no_reset=True)

    def run(self):
        # self.init_button()
        # self.init_menu()
        # self.init_role()
        self.init_users()


# 项目init 初始化，默认会执行 main 方法进行初始化
def main(reset=False):
    Initialize(reset).run()
    pass


if __name__ == '__main__':
    main()
